Load all required libraries.

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.8
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(broom)

Read in raw data from RDS.

raw_data <- readRDS("./n1_n2_cleaned_cases.rds")

Make a few small modifications to names and data for visualizations.

final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
  rename(Facility = wrf) %>%
  mutate(Facility = recode(Facility, 
                           "NO" = "WRF A",
                           "MI" = "WRF B",
                           "CC" = "WRF C"))

Seperate the data by gene target to ease layering in the final plot

#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>% 
  select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
  group_by(date) %>% summarise_if(is.numeric, mean)

#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]

only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]

Build the main plot

      #first layer is the background epidemic curve
        p1 <- only_background %>%
              plotly::plot_ly() %>%
              plotly::add_trace(x = ~date, y = ~new_cases_clarke, 
                                type = "bar", 
                                hoverinfo = "text",
                                text = ~paste('</br> Date: ', date,
                                                     '</br> Daily Cases: ', new_cases_clarke),
                                alpha = 0.5,
                                name = "Daily Reported Cases",
                                color = background_color,
                                colors = background_color,
                                showlegend = FALSE) %>%
            layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
            layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
        
        #renders the main plot layer two as seven day moving average
        p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke, 
                             type = "scatter",
                             mode = "lines",
                             hoverinfo = "text",
                            text = ~paste('</br> Date: ', date,
                                                     '</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
                             name = "Seven Day Moving Average Athens",
                             line = list(color = seven_day_ave_color),
                             showlegend = FALSE)
      

        
        #renders the main plot layer three as positive target hits
        
        p2 <- plotly::plot_ly() %>%
          plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
                                       type = "scatter",
                                       mode = "markers",
                                       hoverinfo = "text",
                                       text = ~paste('</br> Date: ', date,
                                                     '</br> Facility: ', Facility,
                                                     '</br> Target: ', target,
                                                     '</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
                                       data = only_n1,
                                       symbol = ~Facility,
                                       marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
                                       showlegend = FALSE) %>%
          plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
                                       type = "scatter",
                                       mode = "markers",
                                       hoverinfo = "text",
                                       text = ~paste('</br> Date: ', date,
                                                     '</br> Facility: ', Facility,
                                                     '</br> Target: ', target,
                                                     '</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
                                       data = only_n2,
                                       symbol = ~Facility,
                                       marker = list(color = '#D95F02', size = 8, opacity = 0.65),
                                       showlegend = FALSE) %>%
            layout(yaxis = list(title = "SARS CoV-2 Copies/L", 
                                 showline = TRUE,
                                 type = "log",
                                 dtick = 1,
                                 automargin = TRUE)) %>%
            layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
        
        #adds the limit of detection dashed line
        p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"), 
                                          xend = ~max(date + 10), 
                                          y = 3571.429, yend = 3571.429,
                                          opacity = 0.35,
                                          line = list(color = "black", dash = "dash")) %>%
          layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y", 
                                    text = "Limit of Detection", showarrow = FALSE))

        

        p1
        p2

Combine the two main plot pieces as a subplot

#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")

#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")


#rejoin the old data frames then seperate in to averages for each plant. 
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)

Build loess smoothing figures figures

This makes the individual plots

#**************************************WRF A PLOT**********************************************
#add trendlines 
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77', 
              span = 0.25, n = 807)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'

fit_botha
##   [1] 13.05404 13.04920 13.04443 13.03971 13.03504 13.03043 13.02588 13.02137
##   [9] 13.01692 13.01252 13.00817 13.00387 12.99962 12.99541 12.99125 12.98714
##  [17] 12.98307 12.97904 12.97506 12.97113 12.96723 12.96337 12.95956 12.95578
##  [25] 12.95204 12.94834 12.94467 12.94105 12.93745 12.93389 12.93036 12.92687
##  [33] 12.92340 12.91997 12.91657 12.91319 12.90985 12.90653 12.90324 12.89997
##  [41] 12.89672 12.89351 12.89031 12.88714 12.88399 12.88086 12.87776 12.87470
##  [49] 12.87166 12.86866 12.86569 12.86276 12.85988 12.85703 12.85423 12.85147
##  [57] 12.84876 12.84610 12.84350 12.84094 12.83845 12.83601 12.83363 12.83132
##  [65] 12.82907 12.82688 12.82476 12.82272 12.82075 12.81885 12.81703 12.81528
##  [73] 12.81362 12.81204 12.81055 12.80914 12.80782 12.80659 12.80546 12.80442
##  [81] 12.80347 12.80263 12.80189 12.80125 12.80071 12.80023 12.79977 12.79931
##  [89] 12.79887 12.79844 12.79803 12.79764 12.79728 12.79694 12.79663 12.79636
##  [97] 12.79611 12.79591 12.79574 12.79561 12.79552 12.79549 12.79550 12.79556
## [105] 12.79567 12.79584 12.79607 12.79636 12.79671 12.79713 12.79761 12.79817
## [113] 12.79880 12.79950 12.80029 12.80115 12.80210 12.80313 12.80425 12.80546
## [121] 12.80676 12.80816 12.80966 12.81125 12.81295 12.81475 12.81667 12.81869
## [129] 12.82082 12.82307 12.82544 12.82793 12.83054 12.83412 12.83940 12.84623
## [137] 12.85441 12.86379 12.87419 12.88545 12.89738 12.90983 12.92261 12.93556
## [145] 12.94851 12.96129 12.97372 12.98564 12.99687 13.00724 13.01659 13.02474
## [153] 13.03152 13.03676 13.04203 13.04890 13.05725 13.06693 13.07782 13.08978
## [161] 13.10267 13.11636 13.13072 13.14560 13.16087 13.17641 13.19206 13.20770
## [169] 13.22320 13.23841 13.25320 13.26744 13.28099 13.29371 13.30548 13.31615
## [177] 13.32559 13.33367 13.34025 13.34519 13.34837 13.34964 13.34975 13.34956
## [185] 13.34905 13.34821 13.34704 13.34553 13.34366 13.34144 13.33884 13.33588
## [193] 13.33252 13.32878 13.32463 13.32007 13.31510 13.30970 13.30387 13.29759
## [201] 13.29087 13.28368 13.27603 13.26790 13.25929 13.25019 13.24059 13.23048
## [209] 13.21985 13.20870 13.19570 13.17974 13.16109 13.14003 13.11683 13.09178
## [217] 13.06516 13.03725 13.00832 12.97865 12.94853 12.91822 12.88802 12.85819
## [225] 12.82902 12.80079 12.77378 12.74826 12.72452 12.70282 12.68346 12.66418
## [233] 12.64269 12.61923 12.59406 12.56739 12.53949 12.51058 12.48091 12.45071
## [241] 12.42023 12.38971 12.35939 12.32951 12.30030 12.27201 12.24488 12.21916
## [249] 12.19507 12.17286 12.15277 12.13504 12.11929 12.10490 12.09175 12.07976
## [257] 12.06882 12.05881 12.04964 12.04120 12.03339 12.02610 12.01923 12.01267
## [265] 12.00632 12.00007 11.99382 11.98747 11.98090 11.97402 11.96673 11.95891
## [273] 11.95046 11.94128 11.93126 11.92156 11.91331 11.90638 11.90061 11.89587
## [281] 11.89201 11.88889 11.88636 11.88429 11.88252 11.88092 11.87934 11.87765
## [289] 11.87569 11.87332 11.87040 11.86680 11.86235 11.85693 11.85039 11.84258
## [297] 11.83368 11.82400 11.81362 11.80261 11.79105 11.77901 11.76657 11.75380
## [305] 11.74078 11.72758 11.71427 11.70094 11.68765 11.67448 11.66150 11.64880
## [313] 11.63643 11.62449 11.61304 11.60216 11.59192 11.58240 11.57367 11.56581
## [321] 11.55889 11.55299 11.54644 11.53773 11.52712 11.51487 11.50125 11.48652
## [329] 11.47097 11.45484 11.43841 11.42195 11.40571 11.38998 11.37501 11.36108
## [337] 11.34844 11.33737 11.32813 11.32098 11.31621 11.31407 11.31482 11.31757
## [345] 11.32119 11.32565 11.33093 11.33699 11.34381 11.35135 11.35958 11.36847
## [353] 11.37799 11.38811 11.39880 11.41003 11.42176 11.43398 11.44663 11.45971
## [361] 11.47317 11.48698 11.50112 11.51554 11.53024 11.54516 11.56201 11.58233
## [369] 11.60584 11.63226 11.66131 11.69272 11.72621 11.76150 11.79832 11.83638
## [377] 11.87540 11.91512 11.95525 11.99552 12.03564 12.07535 12.11435 12.15238
## [385] 12.18916 12.22441 12.25784 12.28920 12.31819 12.34453 12.36796 12.38820
## [393] 12.40778 12.42926 12.45242 12.47698 12.50272 12.52939 12.55674 12.58452
## [401] 12.61248 12.64039 12.66799 12.69505 12.72131 12.74652 12.77045 12.79284
## [409] 12.81346 12.83205 12.84836 12.86216 12.87320 12.88196 12.88919 12.89498
## [417] 12.89943 12.90264 12.90472 12.90577 12.90589 12.90518 12.90374 12.90167
## [425] 12.89908 12.89607 12.89273 12.88918 12.88550 12.88181 12.87820 12.87478
## [433] 12.87165 12.86890 12.86665 12.86327 12.85725 12.84882 12.83823 12.82572
## [441] 12.81152 12.79589 12.77905 12.76125 12.74272 12.72372 12.70448 12.68523
## [449] 12.66623 12.64770 12.62990 12.61306 12.59742 12.58322 12.57070 12.56011
## [457] 12.55168 12.54319 12.53244 12.51967 12.50512 12.48905 12.47170 12.45332
## [465] 12.43415 12.41445 12.39446 12.37443 12.35460 12.33522 12.31655 12.29882
## [473] 12.28229 12.26720 12.25379 12.24232 12.23304 12.22619 12.22076 12.21561
## [481] 12.21072 12.20612 12.20181 12.19780 12.19409 12.19070 12.18762 12.18487
## [489] 12.18245 12.18038 12.17865 12.17729 12.17628 12.17565 12.17539 12.17553
## [497] 12.17605 12.17698 12.17831 12.18006 12.18224 12.18484 12.18789 12.19137
## [505] 12.19642 12.20401 12.21394 12.22602 12.24005 12.25584 12.27318 12.29189
## [513] 12.31177 12.33261 12.35424 12.37644 12.39902 12.42180 12.44456 12.46712
## [521] 12.48928 12.51085 12.53162 12.55140 12.57000 12.58722 12.60286 12.61673
## [529] 12.62863 12.63837 12.64575 12.65057 12.65423 12.65822 12.66249 12.66699
## [537] 12.67166 12.67645 12.68132 12.68620 12.69106 12.69583 12.70048 12.70493
## [545] 12.70915 12.71308 12.71668 12.71988 12.72264 12.72491 12.72663 12.72776
## [553] 12.72824 12.72802 12.72705 12.72528 12.72265 12.71912 12.71464 12.70915
## [561] 12.70259 12.69493 12.68510 12.67225 12.65670 12.63874 12.61867 12.59677
## [569] 12.57335 12.54871 12.52314 12.49694 12.47041 12.44384 12.41752 12.39177
## [577] 12.36686 12.34311 12.32080 12.30024 12.28171 12.26552 12.25197 12.23834
## [585] 12.22193 12.20305 12.18199 12.15906 12.13455 12.10878 12.08203 12.05462
## [593] 12.02685 11.99901 11.97141 11.94435 11.91814 11.89306 11.86943 11.84755
## [601] 11.82771 11.81023 11.79540 11.78352 11.77259 11.76053 11.74750 11.73367
## [609] 11.71919 11.70425 11.68900 11.67361 11.65825 11.64308 11.62827 11.61399
## [617] 11.60040 11.58767 11.57596 11.56544 11.55628 11.54865 11.54270 11.53862
## [625] 11.53655 11.53667 11.53895 11.54323 11.54939 11.55728 11.56677 11.57770
## [633] 11.58995 11.60337 11.61782 11.63316 11.64925 11.66595 11.68312 11.70063
## [641] 11.71832 11.73606 11.75371 11.77114 11.78819 11.80473 11.82062 11.83572
## [649] 11.84989 11.86298 11.87487 11.88716 11.90145 11.91753 11.93519 11.95425
## [657] 11.97450 11.99573 12.01775 12.04036 12.06335 12.08653 12.10970 12.13265
## [665] 12.15518 12.17709 12.19819 12.21826 12.23712 12.25455 12.27037 12.28436
## [673] 12.29755 12.31105 12.32481 12.33880 12.35296 12.36726 12.38164 12.39606
## [681] 12.41047 12.42484 12.43912 12.45325 12.46720 12.48092 12.49437 12.50750
## [689] 12.52027 12.53262 12.54452 12.55593 12.56678 12.57705 12.58669 12.59583
## [697] 12.60468 12.61324 12.62152 12.62953 12.63729 12.64481 12.65210 12.65917
## [705] 12.66604 12.67272 12.67921 12.68553 12.69170 12.69772 12.70361 12.70938
## [713] 12.71503 12.72059 12.72607 12.73147 12.73657 12.74117 12.74530 12.74900
## [721] 12.75230 12.75524 12.75786 12.76019 12.76226 12.76412 12.76580 12.76734
## [729] 12.76877 12.77013 12.77145 12.77277 12.77413 12.77556 12.77710 12.77879
## [737] 12.78065 12.78273 12.78507 12.78769 12.79064 12.79396 12.79739 12.80068
## [745] 12.80384 12.80689 12.80981 12.81264 12.81537 12.81801 12.82057 12.82305
## [753] 12.82548 12.82785 12.83018 12.83247 12.83473 12.83697 12.83920 12.84142
## [761] 12.84365 12.84589 12.84815 12.85038 12.85250 12.85453 12.85647 12.85833
## [769] 12.86011 12.86182 12.86346 12.86505 12.86658 12.86806 12.86951 12.87091
## [777] 12.87229 12.87365 12.87498 12.87631 12.87763 12.87895 12.88028 12.88162
## [785] 12.88298 12.88437 12.88579 12.88723 12.88869 12.89016 12.89164 12.89313
## [793] 12.89461 12.89609 12.89757 12.89903 12.90048 12.90190 12.90331 12.90468
## [801] 12.90602 12.90733 12.90859 12.90981 12.91098 12.91210 12.91316
#assign fits to a vector
both_trenda <- fit_botha

#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax

#reassign dataframes (just to be safe)
work_botha <- wrfa_both

#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date

#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
                    data = smooth_frame_botha,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_botha,
                                  '</br> Median Log Copies: ', round(both_trenda, digits = 2)),
                    line = list(color = '#1B9E77', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
                                  '</br> Min Log Copies: ', round(both_ymina, digits = 2)),
                    name = "",
                    fillcolor = '#1B9E77',
                    line = list(color = '#1B9E77')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF A") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfa_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#1B9E77', size = 6, opacity = 0.65))

p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines 
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02', 
              span = 0.25, n = 807)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'

fit_bothb
##   [1] 12.62135 12.61683 12.61241 12.60807 12.60382 12.59965 12.59557 12.59157
##   [9] 12.58765 12.58382 12.58008 12.57642 12.57284 12.56934 12.56593 12.56260
##  [17] 12.55935 12.55619 12.55310 12.55010 12.54718 12.54434 12.54158 12.53890
##  [25] 12.53630 12.53378 12.53134 12.52898 12.52669 12.52449 12.52236 12.52032
##  [33] 12.51835 12.51645 12.51464 12.51290 12.51124 12.50965 12.50814 12.50671
##  [41] 12.50535 12.50406 12.50286 12.50173 12.50068 12.49972 12.49884 12.49804
##  [49] 12.49733 12.49671 12.49617 12.49571 12.49534 12.49506 12.49487 12.49476
##  [57] 12.49474 12.49481 12.49496 12.49521 12.49554 12.49597 12.49648 12.49709
##  [65] 12.49778 12.49857 12.49944 12.50041 12.50147 12.50262 12.50387 12.50521
##  [73] 12.50664 12.50817 12.50979 12.51150 12.51331 12.51522 12.51722 12.51932
##  [81] 12.52151 12.52380 12.52619 12.52868 12.53126 12.53403 12.53706 12.54035
##  [89] 12.54387 12.54763 12.55162 12.55582 12.56022 12.56482 12.56960 12.57456
##  [97] 12.57968 12.58496 12.59038 12.59594 12.60163 12.60743 12.61335 12.61935
## [105] 12.62545 12.63162 12.63786 12.64416 12.65050 12.65689 12.66330 12.66974
## [113] 12.67618 12.68262 12.68905 12.69546 12.70184 12.70819 12.71448 12.72071
## [121] 12.72688 12.73297 12.73897 12.74487 12.75066 12.75634 12.76188 12.76729
## [129] 12.77308 12.77970 12.78706 12.79508 12.80365 12.81269 12.82210 12.83180
## [137] 12.84170 12.85170 12.86171 12.87163 12.88139 12.89088 12.90002 12.90872
## [145] 12.91687 12.92440 12.93121 12.93721 12.94230 12.94806 12.95600 12.96593
## [153] 12.97766 12.99100 13.00577 13.02178 13.03884 13.05676 13.07536 13.09445
## [161] 13.11384 13.13334 13.15277 13.17194 13.19067 13.20875 13.22601 13.24227
## [169] 13.25732 13.27099 13.28308 13.29342 13.30181 13.30806 13.31199 13.31439
## [177] 13.31621 13.31744 13.31810 13.31820 13.31774 13.31675 13.31523 13.31319
## [185] 13.31064 13.30759 13.30406 13.30005 13.29557 13.29063 13.28525 13.27944
## [193] 13.27320 13.26654 13.25949 13.25204 13.24420 13.23600 13.22743 13.21851
## [201] 13.20925 13.19966 13.18975 13.17954 13.16902 13.15656 13.14072 13.12184
## [209] 13.10024 13.07625 13.05021 13.02244 12.99328 12.96305 12.93208 12.90071
## [217] 12.86927 12.83807 12.80747 12.77778 12.74933 12.72246 12.69749 12.67476
## [225] 12.65459 12.63732 12.62065 12.60219 12.58214 12.56071 12.53809 12.51448
## [233] 12.49008 12.46510 12.43974 12.41419 12.38865 12.36333 12.33842 12.31414
## [241] 12.29067 12.26821 12.24697 12.22715 12.20895 12.19257 12.17820 12.16564
## [249] 12.15449 12.14463 12.13598 12.12844 12.12191 12.11629 12.11149 12.10742
## [257] 12.10396 12.10104 12.09854 12.09638 12.09445 12.09266 12.09092 12.08912
## [265] 12.08716 12.08496 12.08241 12.07943 12.07590 12.07173 12.06683 12.06110
## [273] 12.05445 12.04829 12.04397 12.04132 12.04014 12.04024 12.04143 12.04351
## [281] 12.04630 12.04961 12.05325 12.05702 12.06074 12.06421 12.06724 12.06965
## [289] 12.07124 12.07183 12.07121 12.06921 12.06562 12.06027 12.05352 12.04592
## [297] 12.03755 12.02849 12.01881 12.00860 11.99793 11.98687 11.97551 11.96392
## [305] 11.95218 11.94037 11.92856 11.91684 11.90527 11.89394 11.88293 11.87230
## [313] 11.86215 11.85254 11.84355 11.83527 11.82777 11.81915 11.80772 11.79378
## [321] 11.77766 11.75969 11.74019 11.71948 11.69788 11.67572 11.65332 11.63101
## [329] 11.60910 11.58793 11.56780 11.54906 11.53202 11.51700 11.50432 11.49432
## [337] 11.48731 11.48362 11.48183 11.48031 11.47910 11.47820 11.47764 11.47743
## [345] 11.47760 11.47817 11.47914 11.48056 11.48242 11.48476 11.48758 11.49092
## [353] 11.49479 11.49921 11.50419 11.50976 11.51594 11.52275 11.53020 11.53832
## [361] 11.54712 11.55663 11.56685 11.57782 11.59090 11.60723 11.62653 11.64852
## [369] 11.67290 11.69941 11.72774 11.75762 11.78875 11.82086 11.85365 11.88685
## [377] 11.92016 11.95330 11.98598 12.01792 12.04884 12.07844 12.10644 12.13256
## [385] 12.15651 12.17801 12.19676 12.21547 12.23683 12.26053 12.28628 12.31376
## [393] 12.34268 12.37274 12.40363 12.43506 12.46671 12.49829 12.52950 12.56003
## [401] 12.58958 12.61785 12.64453 12.66934 12.69195 12.71207 12.72941 12.74364
## [409] 12.75644 12.76958 12.78297 12.79652 12.81014 12.82373 12.83719 12.85043
## [417] 12.86337 12.87589 12.88792 12.89936 12.91011 12.92007 12.92917 12.93729
## [425] 12.94436 12.95026 12.95492 12.95823 12.96010 12.95985 12.95697 12.95166
## [433] 12.94410 12.93449 12.92302 12.90988 12.89526 12.87936 12.86235 12.84445
## [441] 12.82583 12.80669 12.78721 12.76760 12.74804 12.72873 12.70984 12.69159
## [449] 12.67415 12.65772 12.64249 12.62864 12.61639 12.60590 12.59738 12.58837
## [457] 12.57652 12.56211 12.54548 12.52693 12.50678 12.48533 12.46289 12.43979
## [465] 12.41632 12.39281 12.36956 12.34689 12.32511 12.30453 12.28546 12.26821
## [473] 12.25310 12.24043 12.23053 12.22369 12.21824 12.21233 12.20604 12.19945
## [481] 12.19264 12.18568 12.17866 12.17165 12.16473 12.15798 12.15147 12.14530
## [489] 12.13953 12.13424 12.12951 12.12543 12.12206 12.11949 12.11779 12.11705
## [497] 12.11735 12.11875 12.12134 12.12592 12.13309 12.14269 12.15450 12.16836
## [505] 12.18408 12.20146 12.22032 12.24047 12.26174 12.28392 12.30683 12.33030
## [513] 12.35412 12.37812 12.40211 12.42589 12.44929 12.47212 12.49418 12.51531
## [521] 12.53529 12.55396 12.57112 12.58659 12.60018 12.61170 12.62097 12.62983
## [529] 12.64018 12.65189 12.66485 12.67893 12.69400 12.70995 12.72665 12.74398
## [537] 12.76183 12.78006 12.79856 12.81719 12.83585 12.85441 12.87275 12.89074
## [545] 12.90827 12.92520 12.94142 12.95681 12.97125 12.98460 12.99676 13.00759
## [553] 13.01698 13.02481 13.03094 13.03527 13.03766 13.03800 13.03616 13.03203
## [561] 13.02497 13.01466 13.00140 12.98547 12.96719 12.94686 12.92476 12.90121
## [569] 12.87651 12.85094 12.82482 12.79844 12.77211 12.74611 12.72076 12.69636
## [577] 12.67319 12.65157 12.63178 12.61414 12.59894 12.58312 12.56365 12.54092
## [585] 12.51531 12.48720 12.45696 12.42498 12.39164 12.35732 12.32240 12.28725
## [593] 12.25227 12.21782 12.18429 12.15206 12.12151 12.09301 12.06696 12.04373
## [601] 12.02369 12.00723 11.99140 11.97318 11.95287 11.93076 11.90715 11.88232
## [609] 11.85657 11.83019 11.80348 11.77673 11.75023 11.72427 11.69915 11.67517
## [617] 11.65260 11.63175 11.61291 11.59638 11.58243 11.57138 11.56351 11.55821
## [625] 11.55462 11.55262 11.55212 11.55300 11.55518 11.55854 11.56298 11.56840
## [633] 11.57469 11.58175 11.58947 11.59777 11.60652 11.61562 11.62498 11.63449
## [641] 11.64404 11.65354 11.66287 11.67194 11.68064 11.68887 11.69847 11.71114
## [649] 11.72661 11.74457 11.76475 11.78684 11.81057 11.83564 11.86175 11.88863
## [657] 11.91598 11.94351 11.97093 11.99795 12.02429 12.04964 12.07373 12.09626
## [665] 12.11694 12.13549 12.15161 12.16695 12.18332 12.20064 12.21880 12.23774
## [673] 12.25737 12.27761 12.29837 12.31956 12.34111 12.36293 12.38494 12.40705
## [681] 12.42918 12.45125 12.47317 12.49485 12.51622 12.53720 12.55769 12.57761
## [689] 12.59688 12.61542 12.63315 12.64997 12.66581 12.68058 12.69419 12.70698
## [697] 12.71933 12.73127 12.74283 12.75402 12.76488 12.77542 12.78567 12.79567
## [705] 12.80542 12.81496 12.82430 12.83348 12.84252 12.85145 12.86028 12.86904
## [713] 12.87776 12.88646 12.89517 12.90390 12.91255 12.92098 12.92920 12.93721
## [721] 12.94502 12.95262 12.96004 12.96726 12.97430 12.98116 12.98784 12.99436
## [729] 13.00070 13.00689 13.01293 13.01881 13.02454 13.03014 13.03559 13.04092
## [737] 13.04612 13.05119 13.05615 13.06100 13.06573 13.07037 13.07486 13.07918
## [745] 13.08332 13.08728 13.09107 13.09468 13.09812 13.10139 13.10450 13.10744
## [753] 13.11021 13.11282 13.11526 13.11755 13.11968 13.12165 13.12346 13.12512
## [761] 13.12663 13.12799 13.12920 13.13024 13.13112 13.13182 13.13234 13.13270
## [769] 13.13289 13.13292 13.13278 13.13247 13.13200 13.13137 13.13058 13.12963
## [777] 13.12853 13.12727 13.12585 13.12428 13.12256 13.12068 13.11866 13.11649
## [785] 13.11417 13.11170 13.10908 13.10632 13.10339 13.10032 13.09709 13.09371
## [793] 13.09017 13.08648 13.08264 13.07863 13.07447 13.07015 13.06567 13.06103
## [801] 13.05623 13.05127 13.04615 13.04087 13.03542 13.02981 13.02403
#assign fits to a vector
both_trendb <- fit_bothb

#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax

#reassign dataframes (just to be safe)
work_bothb <- wrfb_both

#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date

#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
                    data = smooth_frame_bothb,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothb,
                                  '</br> Median Log Copies: ', round(both_trendb, digits = 2)),
                    line = list(color = '#D95F02', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
                                  '</br> Min Log Copies: ', round(both_yminb, digits = 2)),
                    name = "",
                    fillcolor = '#D95F02',
                    line = list(color = '#D95F02')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF B") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfb_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#D95F02', size = 6, opacity = 0.65))

p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")

#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************

extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A', 
              span = 0.25, n = 807)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'

fit_bothc
##   [1] 12.05825 12.05144 12.04473 12.03812 12.03160 12.02518 12.01885 12.01262
##   [9] 12.00648 12.00043 11.99447 11.98860 11.98283 11.97714 11.97154 11.96603
##  [17] 11.96060 11.95526 11.95000 11.94483 11.93974 11.93473 11.92981 11.92496
##  [25] 11.92019 11.91551 11.91089 11.90636 11.90190 11.89752 11.89321 11.88898
##  [33] 11.88482 11.88073 11.87671 11.87276 11.86888 11.86507 11.86132 11.85765
##  [41] 11.85403 11.85049 11.84701 11.84359 11.84023 11.83694 11.83370 11.83053
##  [49] 11.82741 11.82435 11.82136 11.81844 11.81559 11.81282 11.81012 11.80750
##  [57] 11.80496 11.80251 11.80014 11.79786 11.79566 11.79356 11.79155 11.78963
##  [65] 11.78781 11.78608 11.78446 11.78294 11.78152 11.78021 11.77900 11.77791
##  [73] 11.77692 11.77605 11.77530 11.77466 11.77414 11.77374 11.77347 11.77332
##  [81] 11.77330 11.77340 11.77364 11.77401 11.77451 11.77515 11.77593 11.77685
##  [89] 11.77791 11.77911 11.78046 11.78196 11.78358 11.78528 11.78706 11.78894
##  [97] 11.79091 11.79298 11.79516 11.79743 11.79982 11.80232 11.80494 11.80767
## [105] 11.81053 11.81351 11.81662 11.81987 11.82325 11.82678 11.83044 11.83426
## [113] 11.83822 11.84234 11.84662 11.85106 11.85566 11.86044 11.86538 11.87050
## [121] 11.87580 11.88128 11.88694 11.89280 11.89884 11.90509 11.91153 11.91818
## [129] 11.92503 11.93210 11.93938 11.94687 11.95459 11.96374 11.97540 11.98932
## [137] 12.00526 12.02296 12.04220 12.06272 12.08429 12.10666 12.12959 12.15284
## [145] 12.17616 12.19931 12.22205 12.24414 12.26533 12.28538 12.30405 12.32110
## [153] 12.33628 12.34934 12.36259 12.37832 12.39632 12.41638 12.43830 12.46186
## [161] 12.48686 12.51307 12.54029 12.56831 12.59692 12.62591 12.65507 12.68418
## [169] 12.71304 12.74143 12.76915 12.79598 12.82172 12.84615 12.86905 12.89024
## [177] 12.90948 12.92657 12.94130 12.95345 12.96283 12.96921 12.97332 12.97606
## [185] 12.97748 12.97764 12.97661 12.97444 12.97118 12.96690 12.96166 12.95551
## [193] 12.94851 12.94072 12.93219 12.92299 12.91318 12.90281 12.89193 12.88062
## [201] 12.86892 12.85690 12.84461 12.83212 12.81947 12.80673 12.79395 12.78121
## [209] 12.76854 12.75601 12.74151 12.72315 12.70129 12.67634 12.64866 12.61865
## [217] 12.58669 12.55316 12.51845 12.48293 12.44700 12.41103 12.37541 12.34053
## [225] 12.30676 12.27449 12.24411 12.21599 12.19052 12.16809 12.14908 12.13125
## [233] 12.11222 12.09213 12.07111 12.04930 12.02684 12.00387 11.98052 11.95693
## [241] 11.93323 11.90958 11.88609 11.86292 11.84020 11.81806 11.79665 11.77609
## [249] 11.75654 11.73812 11.72098 11.70524 11.69090 11.67778 11.66578 11.65479
## [257] 11.64473 11.63550 11.62700 11.61912 11.61178 11.60488 11.59831 11.59198
## [265] 11.58580 11.57966 11.57347 11.56712 11.56053 11.55360 11.54622 11.53830
## [273] 11.52974 11.52045 11.51032 11.50037 11.49159 11.48389 11.47715 11.47126
## [281] 11.46614 11.46166 11.45773 11.45424 11.45107 11.44814 11.44533 11.44254
## [289] 11.43965 11.43658 11.43320 11.42942 11.42513 11.42023 11.41460 11.40815
## [297] 11.40081 11.39265 11.38375 11.37418 11.36402 11.35336 11.34226 11.33081
## [305] 11.31909 11.30718 11.29514 11.28307 11.27104 11.25912 11.24740 11.23596
## [313] 11.22487 11.21421 11.20405 11.19449 11.18560 11.17744 11.17011 11.16369
## [321] 11.15824 11.15385 11.14893 11.14202 11.13337 11.12321 11.11181 11.09941
## [329] 11.08624 11.07258 11.05865 11.04471 11.03101 11.01779 11.00530 10.99380
## [337] 10.98352 10.97471 10.96763 10.96251 10.95962 10.95919 10.96148 10.96619
## [345] 10.97278 10.98112 10.99108 11.00254 11.01536 11.02940 11.04455 11.06068
## [353] 11.07764 11.09531 11.11357 11.13228 11.15131 11.17053 11.18981 11.20903
## [361] 11.22804 11.24673 11.26496 11.28260 11.29952 11.31560 11.33255 11.35203
## [369] 11.37384 11.39778 11.42364 11.45120 11.48027 11.51064 11.54209 11.57443
## [377] 11.60745 11.64093 11.67468 11.70849 11.74214 11.77544 11.80817 11.84013
## [385] 11.87111 11.90091 11.92931 11.95612 11.98112 12.00411 12.02489 12.04323
## [393] 12.06089 12.07964 12.09933 12.11979 12.14089 12.16246 12.18434 12.20640
## [401] 12.22847 12.25039 12.27202 12.29320 12.31377 12.33359 12.35250 12.37034
## [409] 12.38696 12.40220 12.41592 12.42796 12.43817 12.44703 12.45516 12.46260
## [417] 12.46938 12.47552 12.48105 12.48601 12.49043 12.49434 12.49776 12.50074
## [425] 12.50329 12.50546 12.50726 12.50874 12.50992 12.51083 12.51150 12.51197
## [433] 12.51226 12.51241 12.51244 12.51150 12.50882 12.50454 12.49879 12.49174
## [441] 12.48351 12.47425 12.46411 12.45323 12.44175 12.42982 12.41758 12.40518
## [449] 12.39275 12.38045 12.36841 12.35678 12.34570 12.33532 12.32578 12.31723
## [457] 12.30980 12.30177 12.29149 12.27920 12.26512 12.24949 12.23255 12.21454
## [465] 12.19568 12.17623 12.15641 12.13645 12.11660 12.09709 12.07816 12.06004
## [473] 12.04297 12.02718 12.01292 12.00041 11.98989 11.98160 11.97410 11.96584
## [481] 11.95693 11.94745 11.93750 11.92718 11.91656 11.90576 11.89486 11.88395
## [489] 11.87314 11.86251 11.85215 11.84216 11.83263 11.82367 11.81535 11.80777
## [497] 11.80103 11.79522 11.79044 11.78677 11.78431 11.78315 11.78340 11.78513
## [505] 11.78880 11.79470 11.80267 11.81254 11.82416 11.83737 11.85201 11.86792
## [513] 11.88495 11.90293 11.92170 11.94112 11.96101 11.98122 12.00159 12.02196
## [521] 12.04217 12.06207 12.08150 12.10029 12.11829 12.13534 12.15128 12.16595
## [529] 12.17920 12.19086 12.20077 12.20879 12.21643 12.22529 12.23525 12.24621
## [537] 12.25806 12.27071 12.28405 12.29797 12.31237 12.32714 12.34219 12.35740
## [545] 12.37268 12.38792 12.40301 12.41785 12.43234 12.44636 12.45983 12.47263
## [553] 12.48466 12.49582 12.50600 12.51509 12.52300 12.52962 12.53484 12.53856
## [561] 12.54068 12.54109 12.53980 12.53698 12.53276 12.52726 12.52062 12.51297
## [569] 12.50444 12.49516 12.48527 12.47488 12.46414 12.45317 12.44210 12.43107
## [577] 12.42021 12.40964 12.39950 12.38992 12.38102 12.37295 12.36582 12.35755
## [585] 12.34617 12.33199 12.31533 12.29650 12.27583 12.25361 12.23018 12.20584
## [593] 12.18092 12.15572 12.13056 12.10577 12.08164 12.05851 12.03668 12.01647
## [601] 11.99820 11.98217 11.96872 11.95815 11.94809 11.93612 11.92246 11.90735
## [609] 11.89102 11.87369 11.85560 11.83697 11.81803 11.79901 11.78014 11.76166
## [617] 11.74378 11.72674 11.71077 11.69610 11.68296 11.67157 11.66217 11.65498
## [625] 11.65024 11.64765 11.64671 11.64732 11.64936 11.65274 11.65734 11.66308
## [633] 11.66983 11.67750 11.68599 11.69519 11.70499 11.71530 11.72600 11.73700
## [641] 11.74819 11.75946 11.77071 11.78184 11.79275 11.80332 11.81346 11.82306
## [649] 11.83202 11.84023 11.84759 11.85541 11.86494 11.87603 11.88848 11.90214
## [657] 11.91682 11.93235 11.94857 11.96529 11.98235 11.99957 12.01677 12.03379
## [665] 12.05046 12.06659 12.08201 12.09656 12.11006 12.12234 12.13322 12.14252
## [673] 12.15122 12.16036 12.16987 12.17972 12.18985 12.20021 12.21075 12.22141
## [681] 12.23214 12.24290 12.25364 12.26429 12.27481 12.28516 12.29527 12.30509
## [689] 12.31458 12.32368 12.33234 12.34052 12.34815 12.35519 12.36159 12.36730
## [697] 12.37236 12.37682 12.38075 12.38418 12.38720 12.38984 12.39217 12.39425
## [705] 12.39613 12.39786 12.39951 12.40114 12.40279 12.40453 12.40641 12.40849
## [713] 12.41083 12.41349 12.41651 12.41996 12.42355 12.42694 12.43014 12.43318
## [721] 12.43606 12.43880 12.44140 12.44388 12.44625 12.44852 12.45071 12.45282
## [729] 12.45487 12.45687 12.45884 12.46078 12.46270 12.46463 12.46656 12.46852
## [737] 12.47051 12.47254 12.47464 12.47681 12.47905 12.48140 12.48376 12.48606
## [745] 12.48830 12.49047 12.49259 12.49464 12.49664 12.49859 12.50048 12.50231
## [753] 12.50409 12.50582 12.50751 12.50914 12.51073 12.51227 12.51376 12.51521
## [761] 12.51662 12.51799 12.51932 12.52059 12.52179 12.52293 12.52401 12.52502
## [769] 12.52597 12.52687 12.52771 12.52850 12.52925 12.52994 12.53059 12.53120
## [777] 12.53177 12.53230 12.53280 12.53327 12.53370 12.53411 12.53449 12.53486
## [785] 12.53519 12.53549 12.53575 12.53597 12.53616 12.53630 12.53641 12.53648
## [793] 12.53650 12.53649 12.53643 12.53633 12.53618 12.53600 12.53576 12.53548
## [801] 12.53516 12.53479 12.53437 12.53390 12.53338 12.53282 12.53220
#assign fits to a vector
both_trendc <- fit_bothc

#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax

#reassign dataframes (just to be safe)
work_bothc <- wrfc_both

#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date

#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
                    data = smooth_frame_bothc,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothc,
                                  '</br> Median Log Copies: ', round(both_trendc, digits = 2)),
                    line = list(color = '#E7298A', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
                                  '</br> Min Log Copies: ', round(both_yminc, digits = 2)),
                    name = "",
                    fillcolor = '#E7298A',
                    line = list(color = '#E7298A')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF C") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfc_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#E7298A', size = 6, opacity = 0.65))

p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")

save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")

save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")